╔═══════════════════════════════════════════════════════════════════════════╗
║                    WHATSDESK PRO - INSTALLATION SETUP                     ║
║          AI-Powered Multilingual WhatsApp CRM & Support System            ║
╚═══════════════════════════════════════════════════════════════════════════╝

📋 TABLE OF CONTENTS
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
1. System Requirements
2. Installation on Windows
3. Installation on Linux
4. Initial Configuration
5. Running the Bot
6. Troubleshooting


═══════════════════════════════════════════════════════════════════════════
1. SYSTEM REQUIREMENTS
═══════════════════════════════════════════════════════════════════════════

✅ Required:
   • Node.js v20.x (LTS - RECOMMENDED, NOT legacy versions!)
   • npm v10.x or higher
   • NVM (Node Version Manager) - Highly recommended
   • Google Cloud account with billing enabled
   • WhatsApp Business account
   • 4GB RAM minimum (8GB recommended)
   • 1GB free disk space
   • Stable internet connection

✅ Recommended:
   • PM2 (for production deployment)
   • Git (for version control)
   • Linux server (Ubuntu 22.04 LTS or later)

⚠️  IMPORTANT: Node.js v20 is the recommended LTS version.
    Older versions (v16, v18) may work but are NOT supported.


═══════════════════════════════════════════════════════════════════════════
2. INSTALLATION ON WINDOWS
═══════════════════════════════════════════════════════════════════════════

📌 STEP 1: Install NVM for Windows (Recommended Method)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

NVM (Node Version Manager) allows you to easily switch between Node.js versions.

1. Download NVM for Windows:
   https://github.com/coreybutler/nvm-windows/releases
   
   Download: nvm-setup.exe (latest version)

2. Run nvm-setup.exe and follow installer

3. Open PowerShell as Administrator

4. Install Node.js v20 (LTS):

   nvm install 20
   nvm use 20

5. Verify installation:

   node --version
   npm --version

   Expected output:
   v20.x.x
   v10.x.x

✅ Benefits of NVM:
   • Easy version switching
   • No conflicts between versions
   • Better for development
   • Industry standard

Alternative (NOT Recommended):
   If you prefer direct installation without NVM:
   https://nodejs.org/ → Download v20.x LTS


📌 STEP 2: Extract WhatsDesk Pro Files
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

After purchasing from Envato Market:

1. Download the ZIP file from CodeCanyon/Envato

2. Extract to a dedicated folder:
   
   Recommended path:
   C:\WhatsDesk-Pro\
   
   Or:
   C:\Users\YourUsername\Documents\WhatsDesk-Pro\

3. Open PowerShell in the extracted folder:
   
   Right-click folder → "Open in Terminal" or "Open PowerShell here"


📌 STEP 3: Install Dependencies
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

In PowerShell (inside bot folder):

   npm install

This will install:
   • @wppconnect-team/wppconnect
   • @google-cloud/translate
   • better-sqlite3
   • moment-timezone
   • dotenv

Wait for installation to complete (2-5 minutes)


📌 STEP 4: Setup Google Cloud (See CONFIGURATION_SETUP.txt)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

1. Create Google Cloud project
2. Enable Translation API
3. Create service account
4. Download JSON key
5. Place in the bot folder it will come with own name please rename it to google-credentials.json


📌 STEP 5: Configure Environment
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

1. Copy .env.example to .env:

   copy .env.example .env

2. Edit .env with Notepad or VS Code:

   notepad .env

3. Configure your settings (see CONFIGURATION_SETUP.txt)


📌 STEP 6: First Run
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

Start the bot:

   npm start

Or for development:

   npm run dev

Expected output:
   
   🤖 Kryzeny Bot iniciando...
   📱 Escaneie o QR Code com WhatsApp
   
   [QR CODE APPEARS HERE]

Scan QR code with WhatsApp > Linked Devices > Link a Device


📌 STEP 7: Running in Background (Production)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

Install PM2:

   npm install -g pm2

Start bot with PM2:

   pm2 start index.js --name kryzeny-bot
   pm2 save
   pm2 startup

Useful PM2 commands:
   
   pm2 status           - Check bot status
   pm2 logs             - View logs
   pm2 restart kryzeny-bot  - Restart bot
   pm2 stop kryzeny-bot     - Stop bot
   pm2 delete kryzeny-bot   - Remove bot


═══════════════════════════════════════════════════════════════════════════
3. INSTALLATION ON LINUX (Ubuntu/Debian)
═══════════════════════════════════════════════════════════════════════════

📌 STEP 1: Update System
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

sudo apt update
sudo apt upgrade -y


📌 STEP 2: Install NVM (Node Version Manager) - RECOMMENDED
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

NVM is the best way to install and manage Node.js versions on Linux.

1. Install NVM:

curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash

2. Reload your shell configuration:

source ~/.bashrc
# or for zsh users:
source ~/.zshrc

3. Install Node.js v20 (LTS):

nvm install 20
nvm use 20
nvm alias default 20

4. Verify installation:

node --version
npm --version

Expected output:
v20.x.x
10.x.x

✅ NVM Benefits:
   • No sudo required
   • Easy version switching
   • Per-project Node versions
   • Better for production

Alternative (NOT Recommended):
   Direct installation via NodeSource:
   curl -fsSL https://deb.nodesource.com/setup_20.x | sudo -E bash -
   sudo apt install -y nodejs


📌 STEP 3: Install Required Dependencies
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

sudo apt install -y build-essential libglib2.0-dev gconf2 libnss3 \
                    libxss1 libasound2 libatk-bridge2.0-0 libgtk-3-0 \
                    git wget unzip


📌 STEP 4: Upload WhatsDesk Pro Files
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

After purchasing from Envato Market:

1. Upload the ZIP file to your server:

# From your local machine:
scp whatsdesk-pro.zip user@your-server:/tmp/

2. On the server, extract:

cd /opt
sudo unzip /tmp/whatsdesk-pro.zip
sudo mv whatsdesk-pro /opt/WhatsDesk-Pro
cd /opt/WhatsDesk-Pro


📌 STEP 5: Set Permissions
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

sudo chown -R $USER:$USER /opt/WhatsDesk-Pro
chmod +x /opt/WhatsDesk-Pro/index.js


📌 STEP 6: Install Dependencies
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

npm install


📌 STEP 7: Setup Google Cloud Credentials
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

1. Upload your google-credentials.json to server:

   # From your local machine:
   scp google-credentials.json user@server:/opt/WhatsDesk-Pro/

2. Or create file directly:

   nano google-credentials.json
   # Paste JSON content
   # Ctrl+X, Y, Enter to save


📌 STEP 8: Configure Environment
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

cp .env.example .env
nano .env

Edit configuration (see CONFIGURATION_SETUP.txt)
Save: Ctrl+X, Y, Enter


📌 STEP 9: First Run (Testing)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

node index.js

Scan QR code with WhatsApp app
Wait for: ✅ Bot conectado com sucesso!


📌 STEP 10: Setup as System Service (Production)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

Option A - Using PM2 (Recommended):

# Install PM2
sudo npm install -g pm2

# Start bot
pm2 start index.js --name whatsdesk-pro

# Auto-start on boot
pm2 startup systemd
pm2 save

# View logs
pm2 logs whatsdesk-pro


Option B - Using systemd:

Create service file:

sudo nano /etc/systemd/system/whatsdesk-pro.service

Add this content:

[Unit]
Description=WhatsDesk Pro - AI Multilingual WhatsApp CRM
After=network.target

[Service]
Type=simple
User=YOUR_USERNAME
WorkingDirectory=/opt/WhatsDesk-Pro
ExecStart=/usr/bin/node /opt/WhatsDesk-Pro/index.js
Restart=always
RestartSec=10
StandardOutput=syslog
StandardError=syslog
SyslogIdentifier=whatsdesk-pro
Environment=NODE_ENV=production

[Install]
WantedBy=multi-user.target

Save and enable:

sudo systemctl daemon-reload
sudo systemctl enable whatsdesk-pro
sudo systemctl start whatsdesk-pro

Check status:

sudo systemctl status whatsdesk-pro

View logs:

sudo journalctl -u whatsdesk-pro -f


═══════════════════════════════════════════════════════════════════════════
4. INITIAL CONFIGURATION
═══════════════════════════════════════════════════════════════════════════

After installation, configure your .env file:

📝 Essential Settings:

   GOOGLE_APPLICATION_CREDENTIALS=./google-credentials.json
   GOOGLE_CLOUD_PROJECT_ID=your-project-id
   DEFAULT_LANGUAGE=en
   ADMIN_NUMBERS=258840000000,258850000000

📝 Optional Settings:

   BUSINESS_HOURS_START=08:00
   BUSINESS_HOURS_END=18:00
   TICKET_TIMEOUT_MINUTES=15
   CLIENT_RESPONSE_TIMEOUT_HOURS=24

See CONFIGURATION_SETUP.txt for detailed explanation


═══════════════════════════════════════════════════════════════════════════
5. RUNNING THE BOT
═══════════════════════════════════════════════════════════════════════════

🚀 Development Mode (with auto-restart):
   
   npm run dev

🚀 Production Mode:
   
   npm start

🚀 With PM2:
   
   pm2 start index.js --name whatsdesk-pro
   pm2 monit  # Monitor in real-time


📊 Commands After Running:

   /ajuda - Show help message
   /abrir ticket - Create new ticket
   /listar tickets - List all tickets (admin only)
   /atender [phone] - Accept ticket (admin only)


═══════════════════════════════════════════════════════════════════════════
6. TROUBLESHOOTING
═══════════════════════════════════════════════════════════════════════════

❌ ERROR: "Cannot find module 'wppconnect'"
   
   Solution:
   npm install
   npm audit fix


❌ ERROR: "Google Cloud credentials not found"
   
   Solution:
   1. Check google-credentials.json exists in bot folder
   2. Check GOOGLE_APPLICATION_CREDENTIALS in .env
   3. Verify file permissions (Linux):
      chmod 644 google-credentials.json


❌ ERROR: "QR Code not showing"
   
   Solution (Linux):
   1. Install missing dependencies:
      sudo apt install chromium-browser chromium-codecs-ffmpeg
   2. Run with --no-sandbox:
      NODE_OPTIONS=--no-sandbox node index.js


❌ ERROR: "Port already in use"
   
   Solution:
   
   Windows:
   netstat -ano | findstr :3000
   taskkill /PID <PID> /F
   
   Linux:
   sudo lsof -i :3000
   sudo kill -9 <PID>


❌ ERROR: "Database locked"
   
   Solution:
   1. Stop all instances of the bot
   2. Delete data/bot.db-journal (if exists)
   3. Restart bot


❌ ERROR: "Translation API quota exceeded"
   
   Solution:
   1. Check Google Cloud Console quota
   2. Enable billing if needed
   3. Request quota increase


🔍 Check Logs:

   Windows:
   - Console output
   - Check data/logs/ folder
   
   Linux:
   - PM2: pm2 logs whatsdesk-pro
   - Systemd: sudo journalctl -u whatsdesk-pro -f


═══════════════════════════════════════════════════════════════════════════
📞 SUPPORT
═══════════════════════════════════════════════════════════════════════════

Need help?
   📱 WhatsApp: https://wa.me/258858119033
   💬 Discord: @maurogashfix

═══════════════════════════════════════════════════════════════════════════

✅ Installation complete! See CONFIGURATION_SETUP.txt for next steps.

═══════════════════════════════════════════════════════════════════════════
